//
//  HLMainController.m
//  weibo-OC
//
//  Created by 黄力 on 15/12/15.
//  Copyright © 2015年 HLTest. All rights reserved.
//

#import "HLMainController.h"
#import "HLHomeController.h"
#import "HLMessageController.h"
#import "HLDiscoverController.h"
#import "HLProfileController.h"
#import "HLMainTabBar.h"
#import "HLComposeController.h"

@interface HLMainController ()

@end

@implementation HLMainController

- (void)viewDidLoad {
    [super viewDidLoad];
    //添加子控制器
    [self addChildViewControllers];
    //通过KVC成自定义tabBar
    HLMainTabBar *mainTabBar = [[HLMainTabBar alloc] init];
    [self setValue:mainTabBar forKey:@"tabBar"];
    //添加点击响应事件
    [mainTabBar.shareBtn addTarget:self action:@selector(clickComposeBtn) forControlEvents:UIControlEventTouchUpInside];
}

//写微博
- (void)clickComposeBtn {
    //modal控制器
    HLComposeController *composeVC = [[HLComposeController alloc] init];
    //添加导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:composeVC];
    //modal
    [self presentViewController:nav animated:YES completion:nil];
}

//添加自控制器
- (void)addChildViewControllers {
    //创建控制器
    HLHomeController *homeVC = [[HLHomeController alloc] init];
    HLMessageController *messageVC = [[HLMessageController alloc] init];
    HLDiscoverController *discoverVC = [[HLDiscoverController alloc] init];
    HLProfileController *profileVC = [[HLProfileController alloc] init];
    //添加
    [self addChildViewController:homeVC withTitle:@"首页" withImageName:@"tabbar_home"];
    [self addChildViewController:messageVC withTitle:@"消息" withImageName:@"tabbar_message_center"];
    [self addChildViewController:discoverVC withTitle:@"发现" withImageName:@"tabbar_discover"];
    [self addChildViewController:profileVC withTitle:@"我" withImageName:@"tabbar_profile"];
}

//提取添加子控制器的方法
- (void)addChildViewController:(UIViewController *)childController withTitle:(NSString *)title withImageName:(NSString *)imageName {
    //添加导航控制器
    UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:childController];
    //设置标题
    childController.title = title;
    //选中状态下颜色
    [childController.tabBarItem setTitleTextAttributes:@{NSForegroundColorAttributeName: [UIColor orangeColor]} forState: UIControlStateSelected];
    //设置图片
    [childController.tabBarItem setImage:[UIImage imageNamed:imageName]];
    //设置选中状态下图片
    [childController.tabBarItem setSelectedImage:[[UIImage imageNamed:[NSString stringWithFormat:@"%@_highlighted",imageName]] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal]];
    //添加
    [self addChildViewController:nav];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



@end
